package com.stox.services.watchlist.repository.impl;

import org.springframework.stereotype.Component;

import com.stox.services.core.repository.AbstractCachingFileRepository;
import com.stox.services.watchlist.repository.WatchlistRepository;
import com.stox.shared.model.Watchlist;

@Component
public class WatchlistFileRepository extends AbstractCachingFileRepository<Watchlist>
		implements WatchlistRepository {

	public WatchlistFileRepository() {
		super("watchlist");
	}

	@Override
	public Watchlist deserialize(String text) {
		return new Watchlist(text);
	}

	@Override
	public String serialize(Watchlist entity) {
		return entity.toString();
	}
	
	@Override
	public Long saveOrUpdate(Watchlist entity) {
		if(null != entity.getId() && 0 == entity.getId()){
			entity.setId(null);
		}
		return super.saveOrUpdate(entity);
	}


}
